package sea.plot;

import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.TableModel;
import sea.util.PublicParam;
import sea.util.SimHyAHelper;
import sea.util.WinHelper;
import simhya.script.ExploredSymbol;
import simhya.script.Symbol;

/**
 *
 * This class builds the layout of Plot3D
 * 
 * @author  Zhirun Ding
 * 
 * Created on 04/07/2012
 * 
 */

public class Plot3DForm extends javax.swing.JDialog {
    
    /** Creates new form Plot3DForm */
    public Plot3DForm(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        typeButtonGroup = new javax.swing.ButtonGroup();
        stattypeButtonGroup = new javax.swing.ButtonGroup();
        backButton = new javax.swing.JButton();
        confirmButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        param1List = new javax.swing.JList();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        param2List = new javax.swing.JList();
        jScrollPane5 = new javax.swing.JScrollPane();
        varList = new javax.swing.JList();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        stattypeLabel = new javax.swing.JLabel();
        averageRadioButton = new javax.swing.JRadioButton();
        varianceRadioButton = new javax.swing.JRadioButton();
        stddevRadioButton = new javax.swing.JRadioButton();
        stderrRadioButton = new javax.swing.JRadioButton();
        cvRadioButton = new javax.swing.JRadioButton();
        fanoRadioButton = new javax.swing.JRadioButton();
        skewRadioButton = new javax.swing.JRadioButton();
        kurtosisRadioButton = new javax.swing.JRadioButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        surfaceRadioButton = new javax.swing.JRadioButton();
        colormapRadioButton = new javax.swing.JRadioButton();
        helpButton = new javax.swing.JButton();

        jPanel2.setName("jPanel2"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sea.SimHyAGui.class).getContext().getResourceMap(Plot3DForm.class);
        setTitle(resourceMap.getString("Plot3DForm.title")); // NOI18N
        setName("Plot3DForm"); // NOI18N
        setResizable(false);
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        backButton.setText(resourceMap.getString("backButton.text")); // NOI18N
        backButton.setName("backButton"); // NOI18N
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });

        confirmButton.setText(resourceMap.getString("confirmButton.text")); // NOI18N
        confirmButton.setName("confirmButton"); // NOI18N
        confirmButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmButtonActionPerformed(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        param1List.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        param1List.setName("param1List"); // NOI18N
        jScrollPane3.setViewportView(param1List);

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        param2List.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        param2List.setName("param2List"); // NOI18N
        jScrollPane4.setViewportView(param2List);

        jScrollPane5.setName("jScrollPane5"); // NOI18N

        varList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        varList.setName("varList"); // NOI18N
        jScrollPane5.setViewportView(varList);

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel1.setName("jPanel1"); // NOI18N

        stattypeLabel.setText(resourceMap.getString("stattypeLabel.text")); // NOI18N
        stattypeLabel.setName("stattypeLabel"); // NOI18N

        stattypeButtonGroup.add(averageRadioButton);
        averageRadioButton.setSelected(true);
        averageRadioButton.setText(resourceMap.getString("averageRadioButton.text")); // NOI18N
        averageRadioButton.setName("averageRadioButton"); // NOI18N

        stattypeButtonGroup.add(varianceRadioButton);
        varianceRadioButton.setText(resourceMap.getString("varianceRadioButton.text")); // NOI18N
        varianceRadioButton.setName("varianceRadioButton"); // NOI18N

        stattypeButtonGroup.add(stddevRadioButton);
        stddevRadioButton.setLabel(resourceMap.getString("stddevRadioButton.label")); // NOI18N
        stddevRadioButton.setName("stddevRadioButton"); // NOI18N

        stattypeButtonGroup.add(stderrRadioButton);
        stderrRadioButton.setLabel(resourceMap.getString("stderrRadioButton.label")); // NOI18N
        stderrRadioButton.setName("stderrRadioButton"); // NOI18N

        stattypeButtonGroup.add(cvRadioButton);
        cvRadioButton.setLabel(resourceMap.getString("cvRadioButton.label")); // NOI18N
        cvRadioButton.setName("cvRadioButton"); // NOI18N

        stattypeButtonGroup.add(fanoRadioButton);
        fanoRadioButton.setLabel(resourceMap.getString("fanoRadioButton.label")); // NOI18N
        fanoRadioButton.setName("fanoRadioButton"); // NOI18N

        stattypeButtonGroup.add(skewRadioButton);
        skewRadioButton.setText(resourceMap.getString("skewRadioButton.text")); // NOI18N
        skewRadioButton.setName("skewRadioButton"); // NOI18N

        stattypeButtonGroup.add(kurtosisRadioButton);
        kurtosisRadioButton.setText(resourceMap.getString("kurtosisRadioButton.text")); // NOI18N
        kurtosisRadioButton.setName("kurtosisRadioButton"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(stattypeLabel)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(stddevRadioButton)
                            .addComponent(averageRadioButton)
                            .addComponent(cvRadioButton)
                            .addComponent(skewRadioButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(kurtosisRadioButton)
                            .addComponent(fanoRadioButton)
                            .addComponent(varianceRadioButton)
                            .addComponent(stderrRadioButton))))
                .addContainerGap(16, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(stattypeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(averageRadioButton)
                    .addComponent(varianceRadioButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(stddevRadioButton)
                    .addComponent(stderrRadioButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cvRadioButton)
                    .addComponent(fanoRadioButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(skewRadioButton)
                    .addComponent(kurtosisRadioButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel3.setName("jPanel3"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        typeButtonGroup.add(surfaceRadioButton);
        surfaceRadioButton.setText(resourceMap.getString("surfaceRadioButton.text")); // NOI18N
        surfaceRadioButton.setName("surfaceRadioButton"); // NOI18N

        typeButtonGroup.add(colormapRadioButton);
        colormapRadioButton.setSelected(true);
        colormapRadioButton.setText(resourceMap.getString("colormapRadioButton.text")); // NOI18N
        colormapRadioButton.setName("colormapRadioButton"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(colormapRadioButton)
                            .addComponent(surfaceRadioButton))))
                .addGap(129, 129, 129))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(surfaceRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(colormapRadioButton)
                .addContainerGap(35, Short.MAX_VALUE))
        );

        helpButton.setText(resourceMap.getString("helpButton.text")); // NOI18N
        helpButton.setName("helpButton"); // NOI18N
        helpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(38, 38, 38)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel4))
                                .addGap(41, 41, 41)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(58, 58, 58)
                        .addComponent(jLabel6)
                        .addGap(163, 163, 163)
                        .addComponent(jLabel7)
                        .addGap(181, 181, 181)
                        .addComponent(jLabel8))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(208, 208, 208)
                        .addComponent(backButton, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(45, 45, 45)
                        .addComponent(confirmButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(helpButton)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel2)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel6)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(backButton)
                            .addComponent(confirmButton)
                            .addComponent(helpButton)))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        if (PublicParam.PreviousForm != null) {
            PublicParam.PreviousForm.setVisible(false);
        }
        
        //get data variables
        String datavar = ((PlotForm)PublicParam.PlotForm).getCurrentDataVariable();
        //System.out.println(datavar + "******************");
                        
        if (lastDataVariable.equals(datavar)) return;//no change
        lastDataVariable = datavar;
        
        //init x-axis list
        ArrayList<ExploredSymbol> evars = PublicParam.SimHyACommand.getExploredParameters(datavar);
        WinHelper.initListbox3(param1List, evars);
        //init y-axis list
        ArrayList<Symbol> vars = PublicParam.SimHyACommand.getVariables(datavar);
        WinHelper.initListbox3(param2List, evars);
        //init z-axis list
        WinHelper.initListbox(varList, vars);
        
        //init fixlist        
//        WinHelper.initTable(fixlistTable, evars);
        
        //statistics type should be enabled only for statistics explorator vars
        boolean enableStatType = false;
        if (PublicParam.SimHyACommand.isStatisticsExploratorVariable(datavar)) {
            enableStatType = true;            
        }
        //for plot3d,   assuming isStatisticsExploratorVariable=true, then
        //if exploratorVariableContainsFinalStateStatistics=true
        //you can plot statistics of final state, and if
        //exploratorVariableContainsTrajectoryStatistics=true
        //you can plot statistics at different time points.
                
        stattypeLabel.setEnabled(enableStatType);
        averageRadioButton.setEnabled(enableStatType);
        varianceRadioButton.setEnabled(enableStatType);
        stddevRadioButton.setEnabled(enableStatType);
        stderrRadioButton.setEnabled(enableStatType);
        cvRadioButton.setEnabled(enableStatType);
        fanoRadioButton.setEnabled(enableStatType);
        skewRadioButton.setEnabled(enableStatType);
        kurtosisRadioButton.setEnabled(enableStatType);        
    }//GEN-LAST:event_formComponentShown

    private void confirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmButtonActionPerformed
        //generate plot command expression
        if (toPlot3DCommand()) {        
            //execute the command
            this.setVisible(false);
            SimHyAHelper.executeCommand();
            //close this form
            this.dispose();
            //clear all forms of plot
            WinHelper.closeFormAfterCommand();
        }
    }//GEN-LAST:event_confirmButtonActionPerformed

    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
        this.setVisible(false);
        
        if (PublicParam.PreviousForm != null) {
            PublicParam.PreviousForm.setVisible(true);
        }
    }//GEN-LAST:event_backButtonActionPerformed

    private void helpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpButtonActionPerformed
        WinHelper.showHelp("plot/plot3d");
    }//GEN-LAST:event_helpButtonActionPerformed
    
    boolean toPlot3DCommand() {
        String s = "";
        //x
        if (param1List.getSelectedValue() == null) {
            JOptionPane.showMessageDialog(this, "Please input x-axis.");     
            return false;
        }
        s += ",x=" + param1List.getSelectedValue().toString();
        
        //y
        if (param2List.getSelectedValue() == null) {
            JOptionPane.showMessageDialog(this, "Please input y-axis.");     
            return false;
        }
        s += ",y=" + param2List.getSelectedValue().toString();
        
        //z
        if (varList.getSelectedIndex() == -1) {
            JOptionPane.showMessageDialog(this, "Please select a model var(z).");     
            return false;
        }
        s += ",z=" + varList.getSelectedValue().toString();        
        
        //fix
//        String fix = "";
//        TableModel tm = fixlistTable.getModel();
//        for (int i = 0; i < tm.getRowCount(); i++) {
//            if (Boolean.valueOf(tm.getValueAt(i, 0).toString())) {
//                if (tm.getValueAt(i, 1).toString().length() > 0 
//                        && tm.getValueAt(i, 2).toString().length() > 0) {
//                    //pname=pvalue
//                    if (fix.length() > 0) fix += ",";
//                    fix += tm.getValueAt(i, 1).toString() + "=[" + tm.getValueAt(i, 2).toString() + "]";
//                }
//            }
//        }
//        if (fix.length() > 0) s += ",fix=[" + fix + "]";
        
        //3D type
        if (surfaceRadioButton.isSelected()) {
            s += ",type=surface";
        } else if (colormapRadioButton.isSelected()) {
            s += ",type=colormap";
        } 
        
        //statistics RadioButton
        if (averageRadioButton.isEnabled() && averageRadioButton.isSelected()) {
            s += ",stat=average";
        } else if (varianceRadioButton.isEnabled() && varianceRadioButton.isSelected()) {
            s += ",stat=variance";
        } else if (stddevRadioButton.isEnabled() && stddevRadioButton.isSelected()) {
            s += ",stat=stddev";
        } else if (stderrRadioButton.isEnabled() && stderrRadioButton.isSelected()) {
            s += ",stat=stderr";
        } else if (cvRadioButton.isEnabled() && cvRadioButton.isSelected()) {
            s += ",stat=cv";
        } else if (fanoRadioButton.isEnabled() && fanoRadioButton.isSelected()) {
            s += ",stat=fano";
        } else if (skewRadioButton.isEnabled() && skewRadioButton.isSelected()) {
            s += ",stat=skew";
        } else if (kurtosisRadioButton.isEnabled() && kurtosisRadioButton.isSelected()) {
            s += ",stat=kurtosis";
        }
        
        PublicParam.SimHyACommandExpression += s + ")";
        PublicParam.CommandTypeName = "Plot3D";     
        return true;
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Plot3DForm dialog = new Plot3DForm(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton averageRadioButton;
    private javax.swing.JButton backButton;
    private javax.swing.JRadioButton colormapRadioButton;
    private javax.swing.JButton confirmButton;
    private javax.swing.JRadioButton cvRadioButton;
    private javax.swing.JRadioButton fanoRadioButton;
    private javax.swing.JButton helpButton;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JRadioButton kurtosisRadioButton;
    private javax.swing.JList param1List;
    private javax.swing.JList param2List;
    private javax.swing.JRadioButton skewRadioButton;
    private javax.swing.ButtonGroup stattypeButtonGroup;
    private javax.swing.JLabel stattypeLabel;
    private javax.swing.JRadioButton stddevRadioButton;
    private javax.swing.JRadioButton stderrRadioButton;
    private javax.swing.JRadioButton surfaceRadioButton;
    private javax.swing.ButtonGroup typeButtonGroup;
    private javax.swing.JList varList;
    private javax.swing.JRadioButton varianceRadioButton;
    // End of variables declaration//GEN-END:variables
    private String lastDataVariable = "";
}
